﻿using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;

namespace _250210作业.Model
{
    public partial class tity : DbContext
    {
        public tity()
            : base("name=tity")
        {
        }

        public virtual DbSet<Authority> Authority { get; set; }
        public virtual DbSet<Department> Department { get; set; }
        public virtual DbSet<Goods> Goods { get; set; }
        public virtual DbSet<GoodsPropertyKey> GoodsPropertyKey { get; set; }
        public virtual DbSet<GoodsPropertyValue> GoodsPropertyValue { get; set; }
        public virtual DbSet<GoodsSpecKey> GoodsSpecKey { get; set; }
        public virtual DbSet<GoodsSpecValue> GoodsSpecValue { get; set; }
        public virtual DbSet<GoodsType> GoodsType { get; set; }
        public virtual DbSet<Images> Images { get; set; }
        public virtual DbSet<Menus> Menus { get; set; }
        public virtual DbSet<Roles> Roles { get; set; }
        public virtual DbSet<Users> Users { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Department>()
                .Property(e => e.deptName)
                .IsUnicode(false);

            modelBuilder.Entity<Department>()
                .Property(e => e.remark)
                .IsUnicode(false);

            modelBuilder.Entity<Department>()
                .HasMany(e => e.Roles)
                .WithRequired(e => e.Department)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Goods>()
                .Property(e => e.name)
                .IsUnicode(false);

            modelBuilder.Entity<Goods>()
                .Property(e => e.content)
                .IsUnicode(false);

            modelBuilder.Entity<Goods>()
                .Property(e => e.images)
                .IsUnicode(false);

            modelBuilder.Entity<Goods>()
                .Property(e => e.unit)
                .IsUnicode(false);

            modelBuilder.Entity<Goods>()
                .Property(e => e.price)
                .HasPrecision(19, 4);

            modelBuilder.Entity<GoodsSpecKey>()
                .Property(e => e.name)
                .IsUnicode(false);

            modelBuilder.Entity<GoodsSpecKey>()
                .HasMany(e => e.GoodsPropertyKey)
                .WithRequired(e => e.GoodsSpecKey)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<GoodsSpecKey>()
                .HasMany(e => e.GoodsSpecValue)
                .WithRequired(e => e.GoodsSpecKey)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<GoodsSpecValue>()
                .Property(e => e.value)
                .IsUnicode(false);

            modelBuilder.Entity<GoodsSpecValue>()
                .Property(e => e.code)
                .IsUnicode(false);

            modelBuilder.Entity<GoodsSpecValue>()
                .HasMany(e => e.GoodsPropertyValue)
                .WithRequired(e => e.GoodsSpecValue)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<GoodsType>()
                .Property(e => e.name)
                .IsUnicode(false);

            modelBuilder.Entity<GoodsType>()
                .Property(e => e.icon)
                .IsUnicode(false);

            modelBuilder.Entity<GoodsType>()
                .HasMany(e => e.Goods)
                .WithRequired(e => e.GoodsType)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Images>()
                .Property(e => e.title)
                .IsUnicode(false);

            modelBuilder.Entity<Images>()
                .Property(e => e.path)
                .IsUnicode(false);

            modelBuilder.Entity<Images>()
                .Property(e => e.extension)
                .IsUnicode(false);

            modelBuilder.Entity<Images>()
                .HasMany(e => e.Users)
                .WithRequired(e => e.Images)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Menus>()
                .Property(e => e.menuName)
                .IsUnicode(false);

            modelBuilder.Entity<Menus>()
                .Property(e => e.url)
                .IsUnicode(false);

            modelBuilder.Entity<Menus>()
                .Property(e => e.icon)
                .IsUnicode(false);

            modelBuilder.Entity<Menus>()
                .HasMany(e => e.Authority)
                .WithRequired(e => e.Menus)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Roles>()
                .Property(e => e.roleName)
                .IsUnicode(false);

            modelBuilder.Entity<Roles>()
                .Property(e => e.remark)
                .IsUnicode(false);

            modelBuilder.Entity<Roles>()
                .HasMany(e => e.Authority)
                .WithRequired(e => e.Roles)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Roles>()
                .HasMany(e => e.Users)
                .WithRequired(e => e.Roles)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Users>()
                .Property(e => e.loginName)
                .IsUnicode(false);

            modelBuilder.Entity<Users>()
                .Property(e => e.loginPwd)
                .IsUnicode(false);

            modelBuilder.Entity<Users>()
                .Property(e => e.userName)
                .IsUnicode(false);

            modelBuilder.Entity<Users>()
                .Property(e => e.sex)
                .IsFixedLength()
                .IsUnicode(false);

            modelBuilder.Entity<Users>()
                .Property(e => e.phone)
                .IsFixedLength()
                .IsUnicode(false);
        }
    }
}
